<?php
class Store_quotaApp extends ApiApp
{
    function __construct()
    {
        $this->Store_quotaApp();
    }

    public function Store_quotaApp()
    {
        parent::__construct();
        $this->store_quota_mod = & m('store_quota');
    }

    public function api_get_store_quota_order()
    {
        $get_time = date('Ym', gmtime());
        //查找当月配额订单
        $order_info = $this->store_quota_mod->get_quota_orderInfo($get_time);
        //取得配置文件中的配额商品id
        $store_quota_file = include_once(SHARE_DATA_PATH . '/data/store_quota.php');
        if (!$store_quota_file) {
            $this->show_warning('store_quota_file_is_no_exits');
            return;
        }
        foreach ($order_info as $key => $val) {
            foreach ($store_quota_file as $quotakey => $quotavalue) {
                $store_quota_goods[$quotakey] = $quotavalue['goods_id'];
                $quota_num[$quotakey] = $quotavalue['quota_num'];
            }
            if ($store_quota_goods[$val['goods_id']]) {
                $o_quota_data['quota_order_info'][$key] = array(
                    'quantity' => $val['quantity'],
                    'quota_store_id' => $val['quota_store_id'],
                    'order_id' => $val['order_id'],
                    'goods_id' => $val['goods_id'],
                    'seller_id' => $val['seller_id'],
                    'seller_name' => $val['seller_name'],
                    'buyer_id' => $val['buyer_id'],
                    'buyer_name' => $val['buyer_name'],
                    'pay_time' => $val['pay_time'],
                    'quota_store_id' => $val['quota_store_id'],
                    'store_name' => $val['store_name'],
                    'quota_num' => $quota_num[$val['goods_id']],
                    'quota_order_num' => $quota_num[$val['goods_id']] * $val['quantity'],
                );
            }
        }
        $cumulative_info = $this->store_quota_mod->get_cumulative_quota_orderInfo($get_time);
        foreach ($cumulative_info as $CQKey => $CQVal) {
            foreach ($store_quota_file as $quotakey => $quotavalue) {
                $store_quota_goods[$quotakey] = $quotavalue['goods_id'];
                $quota_num[$quotakey] = $quotavalue['quota_num'];
            }
            $cumulative_info[$CQKey]['cumulative_num'] = $cumulative_info[$CQKey]['quantity_num'] * $quota_num[$CQVal['goods_id']];
        }
        //获取当月累积配额店铺购买数
        $o_quota_data['cumulative_info'] = $cumulative_info;
        //获取全部累积销售配额
        $all_cumulative_info = $this->store_quota_mod->get_Allcumulative_quota_orderInfo();
        foreach ($all_cumulative_info as $allKey => $allVal) {
            $all_cumulative_info[$allKey]['price'] = $allVal['price'];
            $all_cumulative_info[$allKey]['quantity'] = $allVal['quantity'];
            $all_cumulative_info[$allKey]['all_price'] = $all_cumulative_info[$allKey]['price'] * $all_cumulative_info[$allKey]['quantity'];
            $all_cumulative = $all_cumulative + $all_cumulative_info[$allKey]['all_price'];
        }
        //获取全部累积销售配额
        $o_quota_data['all_cumulative_info'] = $all_cumulative;
        return $this->echo_result($o_quota_data);
    }

}

?>